//
//  ViewController.m
//  绘制图片水印
//
//  Created by 伍银荣 on 2021/7/3.
//  Copyright © 2021 com.image watermarking. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    NSLog(@"----touchesBegan-----");
    //绘制图片水印
    UIImage *image = [UIImage imageNamed:@"花"];
    //开启图片类型的图形上下文
    UIGraphicsBeginImageContextWithOptions(image.size, NO, 0);
    //把图片画上去
    [image drawAtPoint:CGPointZero];
    //绘制文字
    NSString *str = @"花儿好美呀";
    [str drawAtPoint:CGPointMake(20, 20) withAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:30], NSForegroundColorAttributeName: [UIColor redColor]}];
    
    //绘制logo图片
    UIImage *logoImg = [UIImage imageNamed:@"logo"];
    [logoImg drawAtPoint:CGPointMake(image.size.width - logoImg.size.width - 20 , image.size.height - logoImg.size.height - 20)];
    
    //获取图片
    image = UIGraphicsGetImageFromCurrentImageContext();
    //关闭图片类型的图形上下文
    UIGraphicsEndImageContext();
    //把图片保存到系统相册
    UIImageWriteToSavedPhotosAlbum(image, NULL, NULL, NULL);
}


@end
